************************************************************************
* 				TRIBAL TIES REGRESSION TABLES AND PLOTS			       *
************************************************************************

use "data/iraqmerged.dta", clear

lab var nmis "\#Missing responses"
lab var intlsecs "Completion time"

global treatclan i.treat##c.clanperthou
global indvars c.age i.gender i.coledu
global disvars c.pctshia c.sqsect
global regints i.regid i.regid#i.treat
global treatindcovints i.treat#c.age i.treat#i.gender i.treat#i.coledu

global treatcovintsall i.treat#c.age i.treat#i.gender i.treat#i.coledu i.treat#c.pctshia i.treat#c.sqsect
global indvarsall c.age i.gender i.coledu i.wealthcatr i.voted i.hajjbin
global disvarsall c.pctshia c.sqsect c.popdens i.urban c.sqmosdist
global rqualvars c.nmis c.intlsecs

ebalance treat shia age gender coledu pctshia sqsect clanperthou if kurd==0 , targets(1) 

logit natident $treatclan $indvars $disvars $regints $treatindcovints if kurd==0 & shia==0 [pw=_webal]
est sto m1fescint
estadd local regdum "\checkmark"
estadd local regint "\checkmark"
estadd local treatintcovs "\checkmark"

melogit natident $treatclan $indvars $disvars  $treatindcovints if kurd==0 &shia==0 [pw=_webal] || regid: || disid: treat
est sto m1mescint
estadd local regslope "\checkmark"
estadd local treatintcovs "\checkmark"

melogit natident $treatclan $indvars $disvars $treatcovintsall if kurd==0 & shia==0 [pw=_webal] || regid: ||  disid: treat
est sto m2mescint
estadd local regslope "\checkmark"
estadd local treatintcovsall "\checkmark"

melogit natident $treatclan $indvarsall $disvarsall $treatcovintsall $rqualvars if kurd==0 & shia==0 [pw=_webal] || regid: ||  disid: treat
est sto m3mescint
estadd local regslope "\checkmark"
estadd local treatintcovsall "\checkmark"

***TABLE 2***
esttab m1fescint m1mescint using tables/iraqmlbFEMEscint.tex, se starlev(† .1 * .05 ** .01 *** .001) nonotes ///
 nobaselevels eqlabels("" "") varlabels(_cons "Constant" pctshia "\% Shi'i")  collabels("\textit{Coef.}" "\textit{SE}") ///
 mtitle("Nat. ident." "Nat. ident.") ///
 wide label replace cells("b(star fmt(3)) se(fmt(3))") scalars("regdum Province fixed effects" "regint Province*treatment" "treatintcovs Treatment*individual controls" "regslope Treatment random slopes" ) ///
 drop(*.regid *.regid#*.treat *.treat#*.age *.treat#*.gender *.treat#*.coledu) noobs ///
addnotes("{\textit{† p$<$.1, * p$<$.05, ** p$<$.01, *** p$<$.001}}")

***TABLE B.2***

esttab m2mescint m3mescint using tables/iraqmlbFEMEscintac.tex, se starlev(† .1 * .05 ** .01 *** .001) nonotes ///
 nobaselevels eqlabels("" "") varlabels(_cons "Constant" pctshia "\% Shi'i")  collabels("\textit{Coef.}" "\textit{SE}") ///
 mtitle("Nat. ident." "Nat. ident.") ///
 wide label replace cells("b(star fmt(3)) se(fmt(3))") scalars("treatintcovsall Treatment*individual/district controls" "regslope Treatment/sect random slopes") ///
 drop(*.treat#*.age *.treat#*.gender *.treat#*.coledu *.treat#*.pctshia *.treat#*.sqsect) noobs ///
addnotes("{\textit{† p$<$.1, * p$<$.05, ** p$<$.01, *** p$<$.001}}")

***FIGURE 9***

est resto m1fescint

*Pr. Probs.
mgen if treat == 0,	at(clanperthou=(170(1)300)) stub(BM) replace
*Pr. Probs.
mgen if treat == 1,	at(clanperthou=(170(1)300)) stub(AM) replace

lab var 	BMpr1 "Before Mosul"		// Add labels for graph legend
lab var		AMpr1 "After Mosul"

*Create variable for significance information of group differences
gen 		BMSig = BMpr1
gen 		AMSig = AMpr1
lab var 	BMSig "Before Mosul"	
lab var		AMSig "After Mosul"	
*Replace value as missing if group difference is not sig at p<0.05
replace		BMSig = . if AMclanperthou < 3
replace		AMSig = . if AMclanperthou < 3


*NOTE: Showing group differences with a solid line when they are 
*	sig different and a dashed line when not sig. different
twoway  (rarea AMll1 AMul1 AMclanperthou, col(gs14%50)) ///
		(rarea BMll1 BMul1 AMclanperthou, col(gs14%50)) ///
		(connected BMpr1 AMclanperthou, ///
			lpat(dash) lcol(black) lwid(medthick) msym(none)) ///
        (connected BMSig AMclanperthou, ///
			lpat(solid) lcol(black) lwid(medthick) msym(none)) ///
		(connected AMpr1 AMclanperthou, ///
			lpat(dash) lcol(gs10) lwid(medthick) msym(none)) ///
        (connected AMSig AMclanperthou, ///
			lpat(dash) lcol(gs10) lwid(medthick) msym(none)), ///
		xtitle("Tribal ties") ytitle("Pr(Nat. ident.)") title(FE) ///
		legend(order(4 6)) scheme(s1mono) xlab(172(32)300) ylab(0(.5)1) aspectratio(1) name(FEtint, replace)

		

drop BMSig AMSig
		
est resto m1mescint
*Pr. Probs.
mgen if treat == 0,	at(clanperthou=(170(1)300)) stub(BM) replace
*Pr. Probs.
mgen if treat == 1,	at(clanperthou=(170(1)300)) stub(AM) replace

lab var 	BMmargin1 "Before Mosul"		// Add labels for graph legend
lab var		AMmargin1 "After Mosul"

*Create variable for significance information of group differences
gen 		BMSig = BMmargin1
gen 		AMSig = AMmargin1
lab var 	BMSig "Before Mosul"	
lab var		AMSig "After Mosul"	
*Replace value as missing if group difference is not sig at p<0.05
replace		BMSig = . if AMclanperthou < 3
replace		AMSig = . if AMclanperthou < 3


*NOTE: Showing group differences with a solid line when they are 
*	sig different and a dashed line when not sig. different
twoway  (rarea AMll1 AMul1 AMclanperthou, col(gs14%50)) ///
		(rarea BMll1 BMul1 AMclanperthou, col(gs14%50)) ///
		(connected BMmargin1 AMclanperthou, ///
			lpat(dash) lcol(black) lwid(medthick) msym(none)) ///
        (connected BMSig AMclanperthou, ///
			lpat(solid) lcol(black) lwid(medthick) msym(none)) ///
		(connected AMmargin1 AMclanperthou, ///
			lpat(dash) lcol(gs10) lwid(medthick) msym(none)) ///
        (connected AMSig AMclanperthou, ///
			lpat(dash) lcol(gs10) lwid(medthick) msym(none)), ///
		xtitle("Tribal ties") ytitle("Pr(Nat. ident.)") title(ME) ///
		legend(order(4 6)) scheme(s1mono) xlab(172(32)300) ylab(0(.5)1) aspectratio(1) name(MEtint, replace)

		
grc1leg FEtint MEtint, rows(1)
gr_edit style.editstyle boxstyle(shadestyle(color(white))) editcopy
gr_ edit .style.editstyle boxstyle(linestyle(color(none))) editcopy
gr_edit .style.editstyle boxstyle(linestyle(width(none))) editcopy


graph export "plots/FEMEscints.pdf", replace
		
***FIGURE B.5***

drop AMul1 AMmargin1 AMll1 AMul1 AMclanperthou AMSig BMmargin1 BMll1 BMul1 BMclanperthou BMSig

est resto m2mescint

melogit natident $treatclan $indvars $disvars $treatcovintsall if kurd==0 & shia==0 [pw=_webal] || regid: ||  disid: treat
*Pr. Probs.
mgen if treat == 0,	at(clanperthou=(170(1)300)) stub(BM) replace
*Pr. Probs.
mgen if treat == 1,	at(clanperthou=(170(1)300)) stub(AM) replace

lab var 	BMmargin1 "Before Mosul"		// Add labels for graph legend
lab var		AMmargin1 "After Mosul"

*Create variable for significance information of group differences
gen 		BMSig = BMmargin1
gen 		AMSig = AMmargin1
lab var 	BMSig "Before Mosul"	
lab var		AMSig "After Mosul"	
*Replace value as missing if group difference is not sig at p<0.05
replace		BMSig = . if AMclanperthou < 3
replace		AMSig = . if AMclanperthou < 3


*NOTE: Showing group differences with a solid line when they are 
*	sig different and a dashed line when not sig. different
twoway  (rarea AMll1 AMul1 AMclanperthou, col(gs14%50)) ///
		(rarea BMll1 BMul1 AMclanperthou, col(gs14%50)) ///
		(connected BMmargin1 AMclanperthou, ///
			lpat(dash) lcol(black) lwid(medthick) msym(none)) ///
        (connected BMSig AMclanperthou, ///
			lpat(solid) lcol(black) lwid(medthick) msym(none)) ///
		(connected AMmargin1 AMclanperthou, ///
			lpat(dash) lcol(gs10) lwid(medthick) msym(none)) ///
        (connected AMSig AMclanperthou, ///
			lpat(dash) lcol(gs10) lwid(medthick) msym(none)), ///
		xtitle("Tribal ties") ytitle("Pr(Nat. ident.)") title(ME 2) ///
		legend(order(4 6)) scheme(s1mono) xlab(172(32)300) ylab(0(.5)1) aspectratio(1) name(MEtint2, replace)

		
drop AMul1 AMmargin1 AMll1 AMul1 AMclanperthou AMSig BMmargin1 BMll1 BMul1 BMclanperthou BMSig

est resto m3mescint

melogit natident $treatclan $indvarsall $disvarsall $treatcovintsall $rqualvars if kurd==0 & shia==0 [pw=_webal] || regid: ||  disid: treat
*Pr. Probs.
mgen if treat == 0,	at(clanperthou=(170(1)300)) stub(BM) replace
*Pr. Probs.
mgen if treat == 1,	at(clanperthou=(170(1)300)) stub(AM) replace

lab var 	BMmargin1 "Before Mosul"		// Add labels for graph legend
lab var		AMmargin1 "After Mosul"

*Create variable for significance information of group differences
gen 		BMSig = BMmargin1
gen 		AMSig = AMmargin1
lab var 	BMSig "Before Mosul"	
lab var		AMSig "After Mosul"	
*Replace value as missing if group difference is not sig at p<0.05
replace		BMSig = . if AMclanperthou < 3
replace		AMSig = . if AMclanperthou < 3


*NOTE: Showing group differences with a solid line when they are 
*	sig different and a dashed line when not sig. different
twoway  (rarea AMll1 AMul1 AMclanperthou, col(gs14%50)) ///
		(rarea BMll1 BMul1 AMclanperthou, col(gs14%50)) ///
		(connected BMmargin1 AMclanperthou, ///
			lpat(dash) lcol(black) lwid(medthick) msym(none)) ///
        (connected BMSig AMclanperthou, ///
			lpat(solid) lcol(black) lwid(medthick) msym(none)) ///
		(connected AMmargin1 AMclanperthou, ///
			lpat(dash) lcol(gs10) lwid(medthick) msym(none)) ///
        (connected AMSig AMclanperthou, ///
			lpat(dash) lcol(gs10) lwid(medthick) msym(none)), ///
		xtitle("Tribal ties") ytitle("Pr(Nat. ident.)") title(ME 3) ///
		legend(order(4 6)) scheme(s1mono) xlab(172(32)300) ylab(0(.5)1) aspectratio(1) name(MEtint3, replace)

grc1leg MEtint2 MEtint3, rows(1)	
gr_edit style.editstyle boxstyle(shadestyle(color(white))) editcopy
gr_edit .style.editstyle boxstyle(linestyle(color(none))) editcopy
gr_edit.style.editstyle boxstyle(linestyle(width(none))) editcopy

graph export "plots/MEscintsacs.pdf", replace
